/*
 * Copyright © 2017 eqxiu.com 北京中网易企秀科技有限公司  All rights reserved.
 */
package cn.hermit.data.xml.model;

import cn.hermit.data.xml.XML;

/**
 * Java model of XML attribute
 * 
 * @author Jack Gao (Chinese name : GAO JIANGUO, Email : linux.gjg@gmail.com)
 * @date 19 Jun, 2014
 */
public final class XmlAttribute extends XmlNameNode {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4127007717707640208L;

	Object value;

	XmlAttribute() {
	}

	/**
	 * Get the attribute value.
	 * 
	 * @return 
	 * 		The attribute value
	 */
	public Object getValue() {
		if (value == null) {
			value = XML.DEFAULT_NULL_VALUE;
		}
		return value;
	}

	/**
     * Serialize XML Attribute to XML string.
     */
	public String toString() {
		StringBuilder b = new StringBuilder();
		String fullName = XmlNameNode.getName(name);
		b.append(fullName).append("=\"");
		b.append(this.getValue().toString());
		b.append('"');
		return b.toString();
	}

	@Override
	public String toFormatString(int depth, String newLineFeed,boolean newLineForTexts) {
		return toString();
	}
	
	@Override
	public boolean isAttribute() {
		return true;
	}

}